home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / getopt / RCS / getopt.man,v < prev   
Encoding:
Text File  |  1990-10-29  |  1.9 KB  |  117 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @@;
  7.  
  8.  
  9. 1.1
  10. date     90.10.29.12.14.41;  author kupfer;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Man page for getopt script.
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @.TH GETOPT 1 LOCAL
  27. .SH NAME
  28. getopt \- format flags for shell scripts
  29. .SH SYNOPSIS
  30. .B getopt
  31. flag_spec argument ...
  32. .SH DESCRIPTION
  33. .I Getopt
  34. is a program intended to be called by scripts to ``canonicalize'' their
  35. arguments before processing them, just as the
  36. .IR getopt (3)
  37. routine does for C programs.
  38. (This need for scripts is usually most noticeable in the way
  39. .IR lint (1)
  40. handles the
  41. .B \-n
  42. flag.)
  43. .PP
  44. The following two examples provide the initial parsing for a script
  45. which takes two flags,
  46. .B \-a
  47. and
  48. .BR \-b ,
  49. the second of which takes an argument.
  50. .RS
  51. .ta +4n +4n +4n +4n
  52. .nf
  53. # For /bin/csh...
  54. set argv = (`getopt "ab:" $*`)
  55. if ( $status ) then
  56.     echo "Read the documentation and try again." >/dev/tty
  57.     exit 1
  58. endif
  59. set Aflag=0
  60. set Name=NONE
  61. while "$1" != "--"
  62.     switch ("$1")
  63.         case '-a':
  64.             set Aflag=1
  65.             breaksw
  66.         case '-b':
  67.             shift
  68.             set Name=$1
  69.             breaksw
  70.     endsw
  71.     shift
  72. end
  73. shift
  74. echo Aflag=$Aflag / Name=$Name / Remaining args are $*
  75.  
  76. # For /bin/sh...
  77. set -- `getopt "d:s" $@@`
  78. if test $? != 0 ; then
  79.     echo "Read the documentation and try again."
  80.     exit 1
  81. fi
  82. Aflag=0
  83. Name=NONE
  84. for f
  85. do
  86.     case "$f" in
  87.         -a)    Aflag=1
  88.             ;;
  89.         -b)    shift
  90.             Name=$2
  91.             ;;
  92.         --)    break
  93.             ;;
  94.     esac
  95.     shift
  96. done
  97. shift
  98. echo Aflag=$Aflag / Name=$Name / Remaining args are $*
  99. .fi
  100. .RE
  101. .SH DIAGNOSTICS
  102. The program burps the standard
  103. .IR getopt (3)
  104. diagnostics to standard error, and exits with a non-zero status if an
  105. error occurs.
  106. It is arguable wrong that the diagnostics imply that the program
  107. is named ``getopt'' rather than the real name of the script.
  108. It is undeniably AT&T\-compatible to do this, however.
  109. .SH "SEE ALSO"
  110. csh(1), sh(1), getopt(3)
  111. .SH AUTHOR
  112. .nf
  113. Rich $alz
  114. Mirror Systems
  115. (mirror!rs, rs@@mirror.TMC.COM)
  116. @
  117.